package com.qfmy.web.app.service.impl.conmon;

import com.qfmy.model.entity.common.SignRewardRule;
import com.qfmy.model.vo.common.SignRewardRuleVo;
import com.qfmy.web.app.mapper.common.SignRewardRuleMapper;
import com.qfmy.web.app.service.conmon.SignRewardRuleService;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.AutoClose;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * @author 清风明月
 * @Package com.qfmy.web.app.service.impl.conmon
 * @date 2025/11/6
 * @description 签到奖励表
 */
@Service
public class SignRewardRuleServiceImpl implements SignRewardRuleService {

    /**
     * 注入mapper
     */
    @Autowired
    private SignRewardRuleMapper signRewardRuleMapper;

    /**
     * 获取签到奖励规则
     * @return
     */
    @Override
    public List<SignRewardRuleVo> getSignRewardRule() {
        //获取签到奖励规则
        List<SignRewardRule> signRewardRules = signRewardRuleMapper.getSignRewardRule();
        //转换为VO
        return convertToVo(signRewardRules);
    }

    /**
     * 转换为VO
     * @param signRewardRules
     * @return
     */
    @Contract(pure = true)
    private List<SignRewardRuleVo> convertToVo(List<SignRewardRule> signRewardRules) {
        //校验参数
        if (signRewardRules != null && !signRewardRules.isEmpty()) {
            return signRewardRules.stream().map(signRewardRule -> new SignRewardRuleVo(
                    signRewardRule.getDayOfCycle(),
                    signRewardRule.getRewardAmount(),
                    signRewardRule.getVideoTaskCount()
            )).toList();
        }
        return Collections.emptyList();
    }
}
